package locations.model;

import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;


@Entity
public class Institution implements Serializable{
	
	private static final long serialVersionUID = -8869277954802222050L;
	protected String name;
	protected String email;
	protected String detail;
	protected String phoneNumbers;

	@Id @GeneratedValue  
	protected Long id;
	
	@OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)
    @JoinColumn(name="location_id")
	protected Location location;
	
	@ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "responsible_id", nullable = true)
	protected InstitutionResponsible responsible;
		
	@ManyToOne (cascade = CascadeType.ALL) @JoinColumn(name = "institution_type_id", nullable = true)
	protected InstitutionType type;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getPhoneNumbers() {
		return phoneNumbers;
	}

	public void setPhoneNumbers(String phoneNumbers) {
		this.phoneNumbers = phoneNumbers;
	}

	public InstitutionResponsible getResponsible() {
		return responsible;
	}

	public void setResponsible(InstitutionResponsible responsible) {
		this.responsible = responsible;
	}



	public InstitutionType getType() {
		return type;
	}

	public void setType(InstitutionType type)
        {
            if (this.type != null)
            {
                this.type.remove(this);
            }
            this.type = type;
            type.add(this);
                
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}
	
	public boolean isNew()
	{
		return this.id == null;
	}
	
	
}
